<!--!
This file is a part of MediaDrop (http://www.mediadrop.net),
Copyright 2009-2013 MediaCore Inc., Felix Schwarz and other contributors.
For the exact contribution history, see the git revision log.
The source code contained in this file is licensed under the GPLv3 or
(at your option) any later version.
See LICENSE.txt in the main project directory, for more information.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude"
      xmlns:i18n="http://genshi.edgewall.org/i18n"
      py:with="paginator=c.paginators.media">
<xi:include href="../master.html" />
<head>
	<title>Media</title>
	<script src="${h.url_for('/scripts/third-party/squeezebox-1.1-rc4-yui-compressed.js')}" type="text/javascript"></script>
	<link href="${h.url_for('/admin/styles/squeezebox.css')}" media="screen" rel="stylesheet" type="text/css" />
	<link href="${h.url_for('/admin/styles/media.css')}" media="screen" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="${h.url_for('/admin/scripts/confirm.js')}"></script>
	<script type="text/javascript" src="${h.url_for('/admin/scripts/tablemgrs.js')}"></script>
	<script type="text/javascript">
		window.addEvent('domready', function(){
			var table = new BulkTableManager('media-table', {
				prefix: 'media-'
			});
			var bulkDelete = new BulkDelete(table, {
				saveUrl: '${h.url_for(action='bulk', type='delete')}',
				refreshWhenPaginated: true,
				confirmMgr: {
					header: '${_('Confirm Delete').replace("'", "\\'")}',
					msg: function(num){ return '${_('Are you sure you want to delete these %(num)s items?').replace("'", "\\'") % dict(num="'+num+'")}'; },
					confirmButtonText: '${_('Delete').replace("'", "\\'")}',
					cancelButtonText: '${_('Cancel').replace("'", "\\'")}',
				}
			});
			$$('bulk-delete').addEvent('click', bulkDelete.onClick.bind(bulkDelete));
			var bulkPublish = new BulkEdit(table, {
				saveUrl: '${h.url_for(action='bulk', type='publish')}'
			});
			$('bulk-publish').addEvent('click', bulkPublish.onClick.bind(bulkPublish));
			var bulkReview = new BulkEdit(table, {
				saveUrl: '${h.url_for(action='bulk', type='review')}'
			});
			$$('bulk-review').addEvent('click', bulkReview.onClick.bind(bulkReview));

			// XXX: This is a hack to set the selected filter on page load, instead of render time.
			var dropdown = $$('filter-dropdown');
			var selectedText = dropdown.getElement('li.selected span').get('text');
			var button = dropdown.getElement('button.dropdown-toggle');
			button.getElement('span').set('text', selectedText);
			// XXX: There's a race condition here, but its a nonessential event.
			var dd = button.retrieve('Dropdown', null);
			if (dd) dd.addEvent('change', function(selected){
				button.getElement('span').set('text', selected.get('text'));
			});
		});
	</script>
</head>
<body class="menu-media-on">
	<div class="box">
		<div class="box-head clearfix">
			<py:choose>
				<h1 py:when="search" i18n:msg="search">Media that matches '${search}'</h1>
				<h1 py:when="podcast" i18n:msg="podcastTitle">${podcast.title} Episodes</h1>
				<h1 py:when="category" i18n:msg="categoryName">Media in '${category.name}'</h1>
				<h1 py:when="tag" i18n:msg="tagName">Media tagged '${tag.name}'</h1>
				<h1 py:when="media_filter == 'unreviewed'">Unreviewed Media</h1>
				<h1 py:when="media_filter == 'unencoded'">Unencoded Media</h1>
				<h1 py:when="media_filter == 'drafts'">Draft Media</h1>
				<h1 py:when="media_filter == 'published'">Published Media</h1>
				<h1 py:otherwise="">All Media</h1>
			</py:choose>
			<div class="f-rgt">
				<a class="btn inline block f-lft" href="${h.url_for(action='edit', id='new')}" style="margin-right:10px"><span>Add New Media</span></a>
				<div class="dropdown-wrapper f-lft" style="margin-right:10px;width:130px">
					<div class="dropdown-position">
						<div class="dropdown-box">
							<div class="dropdown-top"><div /></div>
							<div class="dropdown-content">
								<ol class="clearfix">
									<li id="bulk-review"><span>Review</span></li>
									<li id="bulk-publish"><span>Publish</span></li>
									<li id="bulk-delete"><span>Delete</span></li>
								</ol>
							</div>
							<div class="dropdown-bottom"><div /></div>
						</div>
					</div>
					<button class="btn inline block dropdown-toggle"><span>Bulk Actions</span></button>
				</div>
				<div class="dropdown-wrapper f-lft" style="margin-right:10px;width:120px" id="filter-dropdown">
					<div class="dropdown-position">
						<div class="dropdown-box">
							<div class="dropdown-top"><div /></div>
							<div class="dropdown-content" py:with="link_args=dict(
								category=category and category.slug or None,
								tag=tag and tag.slug or None,
								podcast=podcast and podcast.slug or None,
							)">
								<ol class="clearfix">
									<li py:with="filter = None; selected = media_filter==filter" class="${selected and 'selected' or None}">
										<a href="${h.url_for(filter=filter, **link_args)}" py:strip="selected"><span py:strip="not selected">All Media</span></a>
									</li>
									<li py:with="filter = 'unreviewed'; selected = media_filter==filter" class="${selected and 'selected' or None}">
										<a href="${h.url_for(filter=filter, **link_args)}" py:strip="selected"><span py:strip="not selected">Unreviewed</span></a>
									</li>
									<li py:with="filter = 'unencoded'; selected = media_filter==filter" class="${selected and 'selected' or None}">
										<a href="${h.url_for(filter=filter, **link_args)}" py:strip="selected"><span py:strip="not selected">Unencoded</span></a>
									</li>
									<li py:with="filter = 'drafts'; selected = media_filter==filter" class="${selected and 'selected' or None}">
										<a href="${h.url_for(filter=filter, **link_args)}" py:strip="selected"><span py:strip="not selected">Drafts</span></a>
									</li>
									<li py:with="filter = 'published'; selected = media_filter==filter" class="${selected and 'selected' or None}">
										<a href="${h.url_for(filter=filter, **link_args)}" py:strip="selected"><span py:strip="not selected">Published</span></a>
									</li>
								</ol>
							</div>
							<div class="dropdown-bottom"><div /></div>
						</div>
					</div>
					<button class="btn inline block dropdown-toggle"><span>Filters</span></button>
				</div>
				<div id="quicksearch" class="f-lft">
					${search_form(dict(search=search))}
				</div>
				<!--!<span class="box-head-sec">${h.doc_link('admin/media', '')}</span>-->
			</div>
		</div>
		<xi:include href="./index-table.html" py:with="
			media=media;
			pager_link_args=dict(
				filter=media_filter,
				category=category and category.slug or None,
				tag=tag and tag.slug or None,
				podcast=podcast and podcast.slug or None,
			);
		" />
	</div>
</body>
</html>
